/** **********************************************************************************
 * @file    6.C.c
 * @mainpage
 * @date    2013-09-29 23:05
 * @author  Alexey Kulikov <alexeyqu@gmail.com>, group 376, DCAM MIPT
 * @version 1.00
 *
 * Check if given numbers can't be divided by square value greater than 1.
 *
 * @par     The task.
 *          The program checks if the given numbers has not square divisors greater than 1.
 *
 * @warning Number should be between 0 and 2^31 and their amount - lower than 200.
**************************************************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>

#define DEBUG

#ifdef DEBUG
    #define DBG printf ("# "),
    #define ASSERT(cond)                                                              \
    if (!(cond))                                                                      \
    {                                                                                 \
        printf ("Critical failure in assertion '%s'! \nfile %s, line %d \n"           \
                "Now keep calm and EXTERMINATE! EXTERMINATE! EXTERMINATE!!!\n"        \
                , #cond, __FILE__, __LINE__);                                         \
        abort();                                                                      \
    }
#else
    #define DBG if (0)
    #define ASSERT(cond)
#endif

/** ********************************************************************************
 * has_square_divisor - checks if argument number has square divisors greater than 1
 *
 * @param   Number  Number to check for divisors
 *
 * @return  1 - divisor exists
 *          0 - divisor doesn't exist
************************************************************************************/
int has_square_divisor (long long int number);

int main()
{
    DBG printf ("C language test'07. \n");
    DBG printf ("6.C problem. \n");
    DBG printf ("Check if number has square divisors greater than 1. \n");
    DBG printf ("Enter amount of numbers to check: \n-> ");

    int amount = 0; //!< Amount of numbers to process
    int res_input = 0; //!< value that controls correct input

    res_input = scanf ("%d", &amount);
    ASSERT (res_input); ASSERT (amount > 0); ASSERT (amount <= 200);

    DBG printf ("Enter numbers to check in one line: (the result will appear on the next line) \n-> ");

    long long int x = 0; //!< Each number in input
    int i = 0; //!< Counter

    for (i = 0; i < amount; i++)
    {
        res_input = scanf ("%lld", &x);
        ASSERT (res_input); ASSERT (x > 0); ASSERT (x < LONG_MAX);

        if (!has_square_divisor (x)) printf ("%lld ", x);
    }

    return 0;
}

int has_square_divisor (long long int number)
{
    int i = 0; //!< Counter

    for (i = 2; i*i <= number; i++)
    {
        if (number % (i*i) == 0) return 1;
    }

    return 0;
}
